{% extends 'accounts/base.html' %}

{% block title %}{{ tool.name }} - 工具详情{% endblock %}

{% block content %}
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
    <h1 class="h2">{{ tool.name }}</h1>
    <div class="btn-toolbar mb-2 mb-md-0">
        <div class="btn-group me-2">
            <a href="{% url 'tools:tool_list' %}" class="btn btn-sm btn-outline-secondary">
                <i class="fas fa-arrow-left"></i> 返回列表
            </a>
            {% if 'tools:tool_update' in user_permissions %}
            <a href="{% url 'tools:tool_update' tool.pk %}" class="btn btn-sm btn-outline-primary">
                <i class="fas fa-edit"></i> 编辑
            </a>
            {% endif %}
            {% if 'tools:tool_delete' in user_permissions %}
            <a href="{% url 'tools:tool_delete' tool.pk %}" class="btn btn-sm btn-outline-danger">
                <i class="fas fa-trash"></i> 删除
            </a>
            {% endif %}
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-8">
        <div class="card">
            <div class="card-header">
                <h5 class="card-title mb-0">工具信息</h5>
            </div>
            <div class="card-body">
                <table class="table table-borderless mb-0">
                    <tr>
                        <th width="20%" class="text-muted">工具名称:</th>
                        <td>{{ tool.name }}</td>
                    </tr>
                    <tr>
                        <th class="text-muted">版本:</th>
                        <td>{{ tool.version|default:"-" }}</td>
                    </tr>
                    <tr>
                        <th class="text-muted">分类:</th>
                        <td>{{ tool.category|default:"-" }}</td>
                    </tr>
                    <tr>
                        <th class="text-muted">所有人:</th>
                        <td>{{ tool.owner.username|default:"-" }}</td>
                    </tr>
                    <tr>
                        <th class="text-muted">校准日期:</th>
                        <td>{{ tool.calibrated_date|date:"Y-m-d"|default:"-" }}</td>
                    </tr>
                    <tr>
                        <th class="text-muted">过期日期:</th>
                        <td>
                            {{ tool.expiration_date|date:"Y-m-d"|default:"-" }}
                            {% if tool.status == 'expired' %}
                                <span class="badge bg-danger ms-2">已过期</span>
                            {% elif tool.status == 'expiring_soon' %}
                                <span class="badge bg-warning text-dark ms-2">快过期</span>
                            {% elif tool.expiration_date %}
                                <span class="badge bg-success ms-2">正常</span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <th class="text-muted">距离过期:</th>
                        <td>
                            {% if tool.days_until_expiration is not None %}
                                {% if tool.days_until_expiration >= 0 %}
                                    还有 {{ tool.days_until_expiration }} 天过期
                                {% else %}
                                    已过期 {{ tool.days_until_expiration }} 天
                                {% endif %}
                            {% else %}
                                -
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <th class="text-muted">状态:</th>
                        <td>
                            {% if tool.is_active %}
                                <span class="badge bg-success">启用</span>
                            {% else %}
                                <span class="badge bg-secondary">禁用</span>
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <th class="text-muted">链接:</th>
                        <td>
                            {% if tool.url %}
                                <a href="{{ tool.url }}" target="_blank">{{ tool.url }}</a>
                            {% else %}
                                -
                            {% endif %}
                        </td>
                    </tr>
                    <tr>
                        <th class="text-muted">创建时间:</th>
                        <td>{{ tool.created_at|date:"Y-m-d H:i:s" }}</td>
                    </tr>
                    <tr>
                        <th class="text-muted">更新时间:</th>
                        <td>{{ tool.updated_at|date:"Y-m-d H:i:s" }}</td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
    
    <div class="col-md-4">
        <div class="card">
            <div class="card-header">
                <h5 class="card-title mb-0">工具描述</h5>
            </div>
            <div class="card-body">
                {% if tool.description %}
                    <p class="mb-0">{{ tool.description|linebreaks }}</p>
                {% else %}
                    <p class="text-muted mb-0">暂无描述</p>
                {% endif %}
            </div>
        </div>
    </div>
</div>
{% endblock %}